package net.sample.gismeteo.gui;

import java.sql.Time;
import java.text.SimpleDateFormat;

import net.sample.gismeteo.Common;
import net.sample.gismeteo.R;
import android.content.Context;
import android.database.Cursor;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CursorAdapter;
import android.widget.TextView;

public class ForecastListAdapter extends CursorAdapter
{

	private LayoutInflater mInflater;
	private int mIdxTS;

	private static final SimpleDateFormat sFormatter = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss");
	
	public ForecastListAdapter(Context pContext, Cursor pCursor)
	{
		super(pContext, pCursor);
		mInflater = LayoutInflater.from(pContext);	
		mIdxTS = pCursor.getColumnIndex(Common.COL_TS);
	}

	@Override
	public void bindView(View pView, Context pContext, Cursor pCursor)
	{
		TextView lText;
		lText = (TextView)pView.findViewById(R.id.labelWhen);
		long lVal = pCursor.getLong(mIdxTS);
		lText.setText(sFormatter.format(new Time(lVal)));
	}

	@Override
	public View newView(Context pContext, Cursor pCursor, ViewGroup pViewgroup)
	{
		View lResult = mInflater.inflate(R.layout.forecastlistitem, null);
		return lResult;
	}
}
